import request from '@/utils/request'
import type { User, UserQuery, UserForm, PaginationResponse } from '@/types'

// 获取用户列表
export const getUserList = (params: UserQuery): Promise<PaginationResponse<User>> => {
  return request.get('/users', { params })
}

// 获取用户详情
export const getUserDetail = (id: number): Promise<User> => {
  return request.get(`/users/${id}`)
}

// 创建用户
export const createUser = (data: UserForm): Promise<void> => {
  return request.post('/users', data)
}

// 更新用户
export const updateUser = (id: number, data: UserForm): Promise<void> => {
  return request.put(`/users/${id}`, data)
}

// 删除用户
export const deleteUser = (id: number): Promise<void> => {
  return request.delete(`/users/${id}`)
}

// 启用/禁用用户
export const toggleUserStatus = (id: number, status: 'active' | 'disabled'): Promise<void> => {
  return request.put(`/users/${id}/status`, { status })
}

// 获取用户统计
export const getUserStats = (): Promise<any> => {
  return request.get('/users/statistics')
}